# _*_ encoding = utf-8 _*_

from datetime import datetime

from django.db import models
from django.core import validators
from django.utils.translation import gettext_lazy as _
from users.models import UserProfile
from courses.models import Course

# Create your models here.


tel_vlidator = validators.RegexValidator(r'1[35678]\d{9}$',_('is not telephone number.'))

class UserAsk(models.Model):
    name = models.CharField(max_length = 20, verbose_name = u'姓名')
    mobile = models.CharField(max_length = 11, verbose_name = u'手机', validators = [tel_vlidator])
    course_name = models.CharField(max_length = 50, verbose_name = u'课程名称')
    add_time = models.DateTimeField(default = datetime.now, verbose_name = u'添加时间')
    class Meta:
        verbose_name = '用户咨询'
        verbose_name_plural = verbose_name


class UserCourse(models.Model):
    user = models.ForeignKey(UserProfile, verbose_name = u'用户', on_delete = models.SET_NULL, null = True)
    course = models.ForeignKey(Course, verbose_name = u'课程', on_delete = models.SET_NULL, null = True)
    add_time = models.DateTimeField(default = datetime.now, verbose_name = u'学习时间')

    class Meta:
        abstract = False
        verbose_name = u'用户课程'
        verbose_name_plural = verbose_name


class CourseComments(UserCourse):
    comment = models.CharField(max_length = 200, verbose_name = u'评论')
    commnet_time = models.DateTimeField(default = datetime.now, verbose_name = u'添加时间')

    class Meta:
        verbose_name = u'课程评论'
        verbose_name_plural = verbose_name


class UserFavorite(models.Model):
    user = models.ForeignKey(UserProfile, verbose_name = u'用户', on_delete = models.SET_NULL, null = True)
    fav_id = models.IntegerField(default = 0, verbose_name = u'数据id')
    fav_type = models.IntegerField(choices = [(1,'课程'),(2,'课程机构'),(3,'讲师')],default = 1,verbose_name = u'收藏类型')
    add_time = models.DateTimeField(default = datetime.now, verbose_name = u'收藏时间')

    class Meta:
        verbose_name = u'用户收藏'
        verbose_name_plural = verbose_name


class UserMessage(models.Model):
    user = models.IntegerField(default = 0, verbose_name = u'用户id')
    message = models.CharField(max_length = 500, verbose_name = u'消息内容')
    has_read = models.BooleanField(default = False, verbose_name = u'是否已读')
    add_time = models.DateTimeField(default = datetime.now, verbose_name = u'发送时间')
    
    class Meta:
        verbose_name = u'用户消息'
        verbose_name_plural = verbose_name


